package com.example.lprxjava;

import android.util.Log;
import android.view.View;

import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Predicate;
import io.reactivex.schedulers.Schedulers;

/**
 * Author by lp,on 2021/7/20/020,14:27.
 * Rxjava 过滤操作符
 */
public class FilterFragement extends BaseFragment {

    private static final String TAG = "FunctionFragement";

    @Override
    String getTAG() {
        return TAG;
    }

    @Override
    String getTitle() {
        return "RxJava 过滤操作符";
    }

    @Override
    int getFragmentLayoutId() {
        return R.layout.flilter_frqagment;
    }

    @Override
    void onLoad(View view) {
        filter();

    }

    //filter 过滤，false就不发送到观察者
    private void filter() {
        Observable<Integer> filter = Observable.range(0, 10)
                .filter(new Predicate<Integer>() {
            @Override
            public boolean test(Integer integer) throws Exception {
                return integer < 6;
            }
        });
        filter.subscribe(observer);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i(TAG, "onDestroyView: ");

    }
}
